//
//  DiseaseCAndRForIpadVC.m
//  RoadMaintain
//
//  Created by 岳学坤 on 2017/3/17.
//  Copyright © 2017年 岳学坤. All rights reserved.
//

#import "DiseaseCAndRForIpadVC.h"
#import "SearchForDiseaseListIPadCell.h"
#import "PutNormolForIPadCell.h"
#import "SearchForDiseaseDetailForIPadCell.h"

#define ListCellID @"cellid1"
#define PutCellID  @"cellid2"
#define DetailCellID @"cellid3"
#define kAlphaNum @".0123456789"
@interface DiseaseCAndRForIpadVC ()<DetailForIPadCellDelegate,UIAlertViewDelegate>
{
    UIAlertView *startAlert;
    NSInteger _selectedIndex;//选中查看第几个
    NSString * _status;//0 保存  1  上报
}
@property (nonatomic) NSInteger state;//0未上报  1已上报
@property (nonatomic,strong) NSArray *titleArray;
@property (nonatomic,strong) NSArray *contentArray;
@property (nonatomic,strong) UIView *rightFooterView;
@property (nonatomic,strong) NSString *codeId;
@property (nonatomic,strong) NSDictionary *dic;//获取的需要展示的ID字典

@property (nonatomic,strong) NSString *resultName;
@property (nonatomic,strong) NSString *resultState;
@property (nonatomic,strong) NSString *detail;
@property (nonatomic,strong) NSString *directorUserId;
@property (nonatomic,strong) NSString *directorUser;
@property (nonatomic,strong) NSString *directorSignDate;
@property (nonatomic,strong) NSString *accepterUserName;
@property (nonatomic,strong) NSString *accepterUserId;
@property (nonatomic,strong) NSString *accepteDate;
@property (nonatomic,strong) NSString *maintentanceMny;
@property (nonatomic,strong) NSString *acceptanceMny;
@end

@implementation DiseaseCAndRForIpadVC

#pragma mark - Life cycle
- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    [self resetNav];
    [self setTableViewFooterView];
    [MBProgressHUD showHUDAddedTo:self.tableView animated:YES];
    [self setWebData];
}
#pragma mark - Property
- (NSArray *)titleArray{
    if (_titleArray==nil) {
       _titleArray = @[@"验收单编码",@"通知单编码",@"管养单位",@"维修保养单位",@"施工开始日期",@"施工结束日期",@"日常养护费用(万元)",@"施工负责人",@"施工负责人签字日期",@"验收结果",@"验收工程费用(万元)",@"验收人",@"验收人签字日期",@"备注"];
    }
    return _titleArray;
}

#pragma mark - UI
- (void)resetNav{
    
    self.leftTitle = @"首页";
    self.pullRefreshEnable = YES;
    self.pullLoadMoreEnable = YES;
    self.myTitle.text = @"养护验收";
    [self.tableView registerClass:[SearchForDiseaseListIPadCell class] forCellReuseIdentifier:ListCellID];
    [self.rightTableView registerClass:[PutNormolForIPadCell class] forCellReuseIdentifier:PutCellID];
    [self.rightTableView registerClass:[SearchForDiseaseDetailForIPadCell class] forCellReuseIdentifier:DetailCellID];
   
}
- (void)setTableViewFooterView{
    
    self.rightFooterView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.rightTableView.frame.size.width, 212*PadHeightRate)];
    self.rightFooterView.backgroundColor = Bai_Color;
    self.rightTableView.tableFooterView = self.rightFooterView;
    
    UIButton *saveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    saveBtn.layer.cornerRadius = 5;
    saveBtn.layer.masksToBounds = YES;
    saveBtn.layer.borderColor = [MAIN_Color CGColor];
    saveBtn.layer.borderWidth = 1;
    saveBtn.backgroundColor = Bai_Color;
    [saveBtn setTitleColor:MAIN_Color forState:UIControlStateNormal];
    [saveBtn setTitle:@"保存" forState:UIControlStateNormal];
    [saveBtn addTarget:self action:@selector(save) forControlEvents:UIControlEventTouchUpInside];
    saveBtn.titleLabel.font = [UIFont systemFontOfSize:17*PadZitiRate];
    [self.rightFooterView addSubview:saveBtn];
    [saveBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-139*PadHeightRate);
        make.height.mas_equalTo(42*PadHeightRate);
        make.left.mas_equalTo(22*PadWidthRate);
        make.right.equalTo(self.rightFooterView.mas_centerX).offset(-15*PadWidthRate);
    }];
    
    
    UIButton *submit = [UIButton buttonWithType:UIButtonTypeCustom];
    submit.layer.cornerRadius = 5;
    submit.layer.masksToBounds = YES;
    submit.backgroundColor = MAIN_Color;
    [submit setTitleColor:Bai_Color forState:UIControlStateNormal];
    [submit setTitle:@"上报" forState:UIControlStateNormal];
    [submit addTarget:self action:@selector(submit) forControlEvents:UIControlEventTouchUpInside];
    submit.titleLabel.font = [UIFont systemFontOfSize:17*PadZitiRate];
    [self.rightFooterView addSubview:submit];
    [submit mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-139*PadHeightRate);
        make.height.mas_equalTo(42*PadHeightRate);
        make.right.mas_equalTo(-22*PadWidthRate);
        make.left.equalTo(self.rightFooterView.mas_centerX).offset(15*PadWidthRate);
    }];
}
#pragma mark - UI Response

- (void)save{
    _status = @"0";
    [self putData];
}
- (void)submit{
    _status = @"1";
    [self putData];
}
- (void)putData{
    
    if([self.resultState length]==0){
        [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"请选择验收结果" animated:YES];
    }else if([self.maintentanceMny length]==0){
        [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"日常养护费用不能为空" animated:YES];
    }else if([self.acceptanceMny length]==0){
        [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"验收工程费用不能为空" animated:YES];
    }else{
        if ([_status integerValue]==1) {
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"上报" message:@"确定上报此养护验收单吗?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
            [alert show];
        }else{
            [self endPutData];
        }
        
    }
    
}
- (void)endPutData{
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [NetWorkTool putUpDiseaseReceive:self.dic[@"maintentanceAcceptanceId"] maintentanceNoticeNo:self.dic[@"maintentanceNoticeNo"] billNo:self.dic[@"billNo"] maintainUnitId:self.dic[@"maintainUnitId"] maintenanceDepartmentId:self.dic[@"maintenanceDepartmentId"] startDate:self.dic[@"startDate"] endDate:self.dic[@"endDate"] directorUser:self.directorUserId directorSignDate:self.directorSignDate state:self.resultState accepterUser:self.accepterUserId accepteSignDate:self.accepteDate remark:self.detail routeId:self.dic[@"routeId"] vcBooleanCode:_status maintentanceMny:self.maintentanceMny acceptanceProjectMny:self.acceptanceMny block:^(id data) {
        [MBProgressHUD hideAllHUDsForView:self.view animated:NO];
        if (data) {
            if ([data[@"success"]integerValue]) {
                
                if ([_status integerValue]==0) {
                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"保存成功" animated:YES];
                }else{
                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"上报成功" animated:YES];
                }
                self.page = 1;
                [self setWebData];
                
            }else{
                if ([data[@"message"] isEqualToString:@"请求需要进行验证,请重新传入Token"]) {
                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"账号被其他设备登录，请重新登录" animated:YES];
                    [self performSelector:@selector(gotoLogin) withObject:nil afterDelay:1];
                }else{
                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:data[@"message"] animated:YES];
                }            }
        }else{
            
            [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"网络错误，操作失败。" animated:YES];
        }
    }];
    
}
- (void)normolState:(NSInteger)state{
    if (state) {
        self.rightTableView.tableFooterView.hidden = YES;
    }else{
        self.rightTableView.tableFooterView.hidden = NO;
    }
    self.myCodeTitle.text = self.dataArray[_selectedIndex][@"billNo"];
}
#pragma mark - Data handle
- (void)setWebData{
    [NetWorkTool diseaseReceiveWithPage:self.page pageSize:10 block:^(id data) {
        [self performSelector:@selector(MJRefreshStop) withObject:nil afterDelay:1];
        [MBProgressHUD hideAllHUDsForView:self.tableView animated:NO];
        if (data) {
            if ([data[@"success"] integerValue]) {
                if (self.page == 1) {
                    self.tableView.contentOffset = CGPointMake(0, 0);
                    [self.dataArray removeAllObjects];
                    _selectedIndex = 0;
                    if ([data[@"data"][@"items"]isKindOfClass:[NSArray class]]) {
                        [self.dataArray addObjectsFromArray:data[@"data"][@"items"]];
                    }
                }else{
                    if ([data[@"data"][@"items"]isKindOfClass:[NSArray class]]) {
                        [self.dataArray addObjectsFromArray:data[@"data"][@"items"]];
                    }
                }
                if ([data[@"data"][@"items"]isKindOfClass:[NSArray class]]) {
                    if ([data[@"data"][@"items"] count]<10&&(self.dataArray.count!=0)) {
                        [self.tableView.mj_footer endRefreshingWithNoMoreData];
                    }
                }
                if (self.dataArray.count == 0) {
                    self.noDataView.hidden = NO;
                    self.rightTableView.tableFooterView.hidden = YES;
                }else{
                    self.noDataView.hidden = YES;
                    NSString *str = [NSString stringWithFormat:@"%@",self.dataArray[0][@"vcBooleanCode"]];
                    if ([str integerValue]) {
                        self.state = 1;
                    }else{
                        self.state = 0;
                    }
                    self.codeId = self.dataArray[0][@"maintentanceAcceptanceId"];
                    [self setWebDataDetail];
                }
                [self normolState:self.state];
                [self.tableView reloadData];
                self.rightTableView.contentOffset = CGPointMake(0, 0);
            }else{
                if ([data[@"message"] isEqualToString:@"请求需要进行验证,请重新传入Token"]) {
                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"账号被其他设备登录，请重新登录" animated:YES];
                    [self performSelector:@selector(gotoLogin) withObject:nil afterDelay:1];
                }else{
                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:data[@"message"] animated:YES];
                }
            }
            
        }else{
            [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"网络错误，请检查网络后重试。" animated:YES
             ];
        }
    }];
}
- (void)setWebDataDetail{
    self.rightTableView.contentOffset = CGPointMake(0, 0);
    [self.rightTableView reloadData];
    [MBProgressHUD showHUDAddedTo:self.rightTableView animated:YES];
    [NetWorkTool diseaseReceiveDetailWithID:self.codeId block:^(id data) {
    [MBProgressHUD hideAllHUDsForView:self.rightTableView animated:NO];
        if (data) {
            if ([data[@"success"] integerValue]) {
                self.dic = data[@"data"][@"DmMaintentanceAcceptanceList"];
                self.resultState =[NSString stringWithFormat:@"%@",self.dic[@"state"]];
                if ([self.resultState integerValue]==1) {
                    self.resultName = @"合格";
                    self.resultState = @"1";
                }else if([self.resultState length]==0){
                    self.resultName = @"请选择";
                    self.resultState = nil;
                }else{
                    self.resultName = @"不合格";
                    self.resultState = @"0";
                }

                self.maintentanceMny = [NSString stringWithFormat:@"%@",self.dic[@"maintentanceMny"]];
                self.acceptanceMny =[NSString stringWithFormat:@"%@",self.dic[@"acceptanceProjectMny"]];
                self.directorUser = self.dic[@"directorUserName"];
                self.directorUserId = self.dic[@"directorUser"];
                self.accepterUserId = self.dic[@"accepterUser"];
                self.accepterUserName = self.dic[@"accepterUserName"];
                self.directorSignDate = self.dic[@"directorSignDate"];
                self.accepteDate = self.dic[@"accepteSignDate"];
                self.detail = self.dic[@"remark"];
                [self.rightTableView reloadData];
            }else{
                if ([data[@"message"] isEqualToString:@"请求需要进行验证,请重新传入Token"]) {
                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"账号被其他设备登录，请重新登录" animated:YES];
                    [self performSelector:@selector(gotoLogin) withObject:nil afterDelay:1];
                }else{
                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:data[@"message"] animated:YES];
                }
            }
        }else{
            [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"网络错误，请检查网络后重试。" animated:YES];
        }
    }];}
- (void)gotoLogin{
    [PublicMethod noTokenToLoginWithNav:self.navigationController];
}

#pragma mark - Delegate
- (void)detailForIPadCellWithString:(NSString *)str indexPath:(NSIndexPath *)indexPath{
    self.detail = str;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if ([tableView isEqual:self.tableView]) {
        return self.dataArray.count;
        
    }else{
        return 14;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([tableView isEqual:self.tableView]) {
        SearchForDiseaseListIPadCell *cell = (SearchForDiseaseListIPadCell *)[self tableView:self.tableView cellForRowAtIndexPath:indexPath];
        return cell.cellHeight;
    }else{
        if (indexPath.row==0) {
            return 68*PadHeightRate;
        }else if(indexPath.row == 13){
            return 152*PadHeightRate;
        }
        else{
            return 50*PadHeightRate;
        }
    }
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([tableView isEqual:self.tableView]) {
        SearchForDiseaseListIPadCell *cell = [tableView dequeueReusableCellWithIdentifier:ListCellID];
        if (_selectedIndex == indexPath.row) {
            cell.contentView.backgroundColor = Bai_Color;
            
            cell.contentView.layer.borderWidth = 0;
            cell.blueLine.hidden = NO;
        }else{
            cell.contentView.backgroundColor = [PublicMethod colorWithHexString:@"#f4f4f4" andAlpha:1];
            cell.contentView.layer.borderColor = [Line_Color CGColor];
            cell.contentView.layer.borderWidth = 1;
            cell.blueLine.hidden = YES;
        }
        [cell diseaseReceiveAddValue:self.dataArray[indexPath.row]];
        return cell;
    }else{
        if(indexPath.row ==13){
            SearchForDiseaseDetailForIPadCell *cell = [tableView dequeueReusableCellWithIdentifier:DetailCellID];
            cell.titleLab.text = @"备注";
            cell.delegate = self;
            cell.indexPath = indexPath;
            if (self.state == 1) {
                cell.detailTextView.editable = NO;
                if ([self.detail length]==0) {
                    cell.detailTextView.text = @" ";
                }else{
                    cell.detailTextView.text= self.detail;
                }
            }else{
                cell.detailTextView.editable = YES;
                cell.detailTextView.placeholder = @"请输入备注内容";
                cell.detailTextView.text = self.detail;
            }
            return cell;
        }else{
            PutNormolForIPadCell *cell = [tableView dequeueReusableCellWithIdentifier:PutCellID];
            cell.titleLab.text = self.titleArray[indexPath.row];
            switch (indexPath.row) {
                case 0:
                {
                    cell.contentLab.text = self.dic[@"billNo"];
                }
                    break;
                case 1:
                {
                    cell.contentLab.text= self.dic[@"maintentanceNoticeNo"];
                }
                    break;
                case 2:
                {
                    cell.contentLab.text = self.dic[@"maintainUnitName"];
                }
                    break;
                case 3:
                {
                    cell.contentLab.text = self.dic[@"maintenanceDepartment"];
                }
                    break;
                case 4:
                {
                    cell.contentLab.text = self.dic[@"startDate"];
                }
                    break;
                case 5:
                {
                    cell.contentLab.text = self.dic[@"endDate"];
                }
                    break;
                case 6:
                {
                    cell.contentLab.text = [PublicMethod changeFloat:[NSString stringWithFormat:@"%.6f",[self.maintentanceMny doubleValue]]];
                    [cell.titleLab mas_updateConstraints:^(MASConstraintMaker *make) {
                        make.centerY.mas_equalTo(0);
                        make.height.mas_equalTo(36*PadHeightRate);
                        make.left.mas_equalTo(12*PadWidthRate);
                        make.width.mas_equalTo(120*PadWidthRate);
                    }];
                }
                    break;
                case 7:
                {
                    cell.contentLab.text = self.directorUser;
                    
                }
                    break;
                case 8:
                {
                    cell.contentLab.text = self.directorSignDate;
                    [cell.titleLab mas_updateConstraints:^(MASConstraintMaker *make) {
                        make.centerY.mas_equalTo(0);
                        make.height.mas_equalTo(36*PadHeightRate);
                        make.left.mas_equalTo(12*PadWidthRate);
                        make.width.mas_equalTo(120*PadWidthRate);
                    }];
                }
                    break;
                case 9:
                {
                    cell.contentLab.text = self.resultName;
                }
                    break;
                case 10:
                {
                    cell.contentLab.text = [PublicMethod changeFloat:[NSString stringWithFormat:@"%.6f",[self.acceptanceMny doubleValue]]];
                    [cell.titleLab mas_updateConstraints:^(MASConstraintMaker *make) {
                        make.centerY.mas_equalTo(0);
                        make.height.mas_equalTo(36*PadHeightRate);
                        make.left.mas_equalTo(12*PadWidthRate);
                        make.width.mas_equalTo(120*PadWidthRate);
                    }];
                }
                    break;
                case 11:
                {
                    cell.contentLab.text  = self.accepterUserName;
                }
                    break;
                case 12:
                {
                    cell.contentLab.text = self.accepteDate;
                    [cell.titleLab mas_updateConstraints:^(MASConstraintMaker *make) {
                        make.centerY.mas_equalTo(0);
                        make.height.mas_equalTo(36*PadHeightRate);
                        make.left.mas_equalTo(12*PadWidthRate);
                        make.width.mas_equalTo(120*PadWidthRate);
                    }];
                    
                }
                    break;
                default:
                    break;
            }
            if (self.state==1) {
                cell.img.hidden = YES;
            }else{
                if (indexPath.row==6||indexPath.row==7||indexPath.row==8||indexPath.row==9||indexPath.row==10||indexPath.row==11||indexPath.row==12) {
                    cell.img.hidden = NO;
                    cell.img.image = [UIImage imageNamed:@"enter"];
                }else{
                    cell.img.hidden = YES;
                }
            }
        return cell;
        }
    }
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([tableView isEqual:self.tableView]) {
        _selectedIndex = indexPath.row;
        [self.tableView reloadData];
        self.codeId = self.dataArray[indexPath.row][@"maintentanceAcceptanceId"];
        NSString *str = [NSString stringWithFormat:@"%@",self.dataArray[indexPath.row][@"vcBooleanCode"]];
        if ([str integerValue]) {
            self.state = 1;
        }else{
            self.state = 0;
        }
        [self setWebDataDetail];
        [self normolState:self.state];
    }else{
        if (self.state!=1) {
            switch (indexPath.row) {
                case 6:
                {
                    startAlert = [[UIAlertView alloc]initWithTitle:@"请输入日常养护费用(万元)" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
                    [startAlert setAlertViewStyle:UIAlertViewStylePlainTextInput];
                    UITextField *startField = [startAlert textFieldAtIndex:0];
                    startField.placeholder = @"请输入费用(万元)";
                    startField.keyboardType = UIKeyboardTypeDecimalPad;
                    if ([self.maintentanceMny doubleValue]==0) {
                        startField.text = nil;
                    }else{
                        startField.text = self.maintentanceMny;
                    }
                    [startField becomeFirstResponder];
                    [startAlert show];
                }
                    break;
                case 7:
                {
                    [MBProgressHUD showHUDAddedTo:self.rightTableView animated:YES];
                    [NetWorkTool receiveManWithUnitID:nil block:^(id data) {
                        [MBProgressHUD hideAllHUDsForView:self.rightTableView animated:NO];
                        if (data) {
                            if([data[@"success"] integerValue]){
                                UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"施工负责人" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
                                 PutNormolForIPadCell *cell = (PutNormolForIPadCell *)[self.rightTableView cellForRowAtIndexPath:indexPath];
                                for (int i = 0; i<[data[@"data"] count]; i++) {
                                    [actionSheet addAction:[UIAlertAction actionWithTitle:[NSString stringWithFormat:@"%@",data[@"data"][i][@"userName"]]style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                                        self.directorUser = data[@"data"][i][@"userName"];
                                        self.directorUserId = data[@"data"][i][@"userId"];
                                       
                                        cell.contentLab.text = self.directorUser;
                                        
                                    }]];
                                }
                                
                                dispatch_async(dispatch_get_main_queue(), ^{
                                    actionSheet.popoverPresentationController.sourceView = cell.bgView;
                                    actionSheet.popoverPresentationController.sourceRect = CGRectMake(cell.bgView.frame.size.width-15*PadWidthRate,(CGFloat)cell.bgView.frame.size.height/(CGFloat)2.0,1.0,1.0);
                                    [self presentViewController:actionSheet animated:YES completion:nil];
                                });
                                
                            }else{
                                
                                [PublicMethod noTokenToLoginWithNav:self.navigationController];
                            }
                            
                        }else{
                            [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"因网络问题获取施工负责人失败" animated:YES];
                        }
                        
                    }];
                    
                }
                    break;
                    
                case 8:
                {
                    //x,y 值无效，默认是居中的
                    KSDatePicker* picker = [[KSDatePicker alloc] initWithFrame:CGRectMake(0, 0, 280, 260)];
                    
                    //配置中心，详情见KSDatePikcerApperance
                    
                    picker.appearance.radius = 5;
                    
                    //设置回调
                    picker.appearance.resultCallBack = ^void(KSDatePicker* datePicker,NSDate* currentDate,KSDatePickerButtonType buttonType){
                        
                        if (buttonType == KSDatePickerButtonCommit) {
                            
                            NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
                            [formatter setDateFormat:@"yyyy-MM-dd"];
                            self.directorSignDate = [formatter stringFromDate:currentDate];
                            PutNormolForIPadCell *cell = (PutNormolForIPadCell *)[self.rightTableView cellForRowAtIndexPath:indexPath];
                            cell.contentLab.text = self.directorSignDate;
                        }
                    };
                    // 显示
                    [picker show];
                    
                }
                    break;
                    
                case 9:
                {
                    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"验收结果" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
                    PutNormolForIPadCell *cell = (PutNormolForIPadCell *)[self.rightTableView cellForRowAtIndexPath:indexPath];
                    [actionSheet addAction:[UIAlertAction actionWithTitle:@"合格" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                        self.resultState = @"1";
                        self.resultName = @"合格";
                        
                        PutNormolForIPadCell *cell = (PutNormolForIPadCell *)[self.rightTableView cellForRowAtIndexPath:indexPath];
                        cell.contentLab.text = self.resultName;
                    }]];
                    [actionSheet addAction:[UIAlertAction actionWithTitle:@"不合格" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                        self.resultState = @"0";
                        self.resultName = @"不合格";
                        
                        PutNormolForIPadCell *cell = (PutNormolForIPadCell *)[self.rightTableView cellForRowAtIndexPath:indexPath];
                        cell.contentLab.text = self.resultName;
                    }]];
                    
                    dispatch_async(dispatch_get_main_queue(), ^{
                        actionSheet.popoverPresentationController.sourceView = cell.bgView;
                        actionSheet.popoverPresentationController.sourceRect = CGRectMake(cell.bgView.frame.size.width-15*PadWidthRate,(CGFloat)cell.bgView.frame.size.height/(CGFloat)2.0,1.0,1.0);
                        [self presentViewController:actionSheet animated:YES completion:nil];
                    });

                    
                }
                    break;
                    
                case 10:
                {
                    startAlert = [[UIAlertView alloc]initWithTitle:@"请输入验收工程费用(万元)" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
                    [startAlert setAlertViewStyle:UIAlertViewStylePlainTextInput];
                    UITextField *startField = [startAlert textFieldAtIndex:0];
                    startField.placeholder = @"请输入费用(万元)";
                    startField.keyboardType = UIKeyboardTypeDecimalPad;
                    if ([self.acceptanceMny doubleValue]==0) {
                        startField.text = nil;
                    }else{
                        startField.text = self.acceptanceMny;
                    }
                    [startField becomeFirstResponder];
                    [startAlert show];
                }
                    break;
                    
                case 11:
                {
                    [MBProgressHUD showHUDAddedTo:self.rightTableView animated:YES];
                    [NetWorkTool receiveManWithUnitID:nil block:^(id data) {
                        [MBProgressHUD hideAllHUDsForView:self.rightTableView animated:NO];
                        if (data) {
                            if([data[@"success"] integerValue]){
                                UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"验收人" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
                                  PutNormolForIPadCell *cell = (PutNormolForIPadCell *)[self.rightTableView cellForRowAtIndexPath:indexPath];
                                for (int i = 0; i<[data[@"data"] count]; i++) {
                                    [actionSheet addAction:[UIAlertAction actionWithTitle:[NSString stringWithFormat:@"%@",data[@"data"][i][@"userName"]]style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                                        self.accepterUserName = data[@"data"][i][@"userName"];
                                        self.accepterUserId = data[@"data"][i][@"userId"];
                                      
                                        cell.contentLab.text = self.accepterUserName;
                                        
                                    }]];
                                }
                                
                                dispatch_async(dispatch_get_main_queue(), ^{
                                    actionSheet.popoverPresentationController.sourceView = cell.bgView;
                                    actionSheet.popoverPresentationController.sourceRect = CGRectMake(cell.bgView.frame.size.width-15*PadWidthRate,(CGFloat)cell.bgView.frame.size.height/(CGFloat)2.0,1.0,1.0);
                                    [self presentViewController:actionSheet animated:YES completion:nil];
                                });
                                
                            }else{
                                
                                [PublicMethod noTokenToLoginWithNav:self.navigationController];
                            }
                            
                        }else{
                            [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"因网络问题获取验收人失败" animated:YES];
                        }
                        
                    }];
                    
                }
                    break;
                    
                case 12:
                {
                    //x,y 值无效，默认是居中的
                    KSDatePicker* picker = [[KSDatePicker alloc] initWithFrame:CGRectMake(0, 0, 280, 260)];
                    
                    //配置中心，详情见KSDatePikcerApperance
                    
                    picker.appearance.radius = 5;
                    
                    //设置回调
                    picker.appearance.resultCallBack = ^void(KSDatePicker* datePicker,NSDate* currentDate,KSDatePickerButtonType buttonType){
                        
                        if (buttonType == KSDatePickerButtonCommit) {
                            
                            NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
                            [formatter setDateFormat:@"yyyy-MM-dd"];
                            self.accepteDate = [formatter stringFromDate:currentDate];
                            PutNormolForIPadCell *cell = (PutNormolForIPadCell *)[self.rightTableView cellForRowAtIndexPath:indexPath];
                            cell.contentLab.text = self.accepteDate;
                        }
                    };
                    // 显示
                    [picker show];
                    
                }
                    break;
                    
                default:
                    break;
            }
          
        }
    }
    
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if ([alertView.title isEqualToString:@"上报"]) {
        if (buttonIndex) {
            [self endPutData];
        }
    }else if ([alertView.title isEqualToString:@"请输入日常养护费用(万元)"]) {
        if (buttonIndex == alertView.firstOtherButtonIndex) {
            UITextField* textField = [alertView textFieldAtIndex:0];
            if([textField.text removeSpace].length==0){
                [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"输入金额为空" animated:YES];
                return;
            }else{
                NSCharacterSet *cs;
                cs = [[NSCharacterSet characterSetWithCharactersInString:kAlphaNum] invertedSet];
                
                NSString *filtered = [[textField.text componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""]; //按cs分离出数组,数组按@""分离出字符串
                self.maintentanceMny =[PublicMethod changeFloat:[NSString stringWithFormat:@"%f",[filtered doubleValue]]];
                
                PutNormolForIPadCell *cell = (PutNormolForIPadCell *)[self.rightTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:6 inSection:0]];
                cell.contentLab.text = self.maintentanceMny;
            }
        }
    }else{
        if (buttonIndex == alertView.firstOtherButtonIndex) {
            UITextField* textField = [alertView textFieldAtIndex:0];
            if([textField.text removeSpace].length==0){
                [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"输入金额为空" animated:YES];
                return;
            }else{
                NSCharacterSet *cs;
                cs = [[NSCharacterSet characterSetWithCharactersInString:kAlphaNum] invertedSet];
                
                NSString *filtered = [[textField.text componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""]; //按cs分离出数组,数组按@""分离出字符串
                self.acceptanceMny =[PublicMethod changeFloat:[NSString stringWithFormat:@"%f",[filtered doubleValue]]];
                
                PutNormolForIPadCell *cell = (PutNormolForIPadCell *)[self.rightTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:10 inSection:0]];
                cell.contentLab.text = self.acceptanceMny;
            }
        }
    }
}
@end
